package com.sky.mapper;

import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;
import java.util.List;

@Mapper
public interface SetmealDishMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    /**
     * 根据dishIds 查询 SetmealDish中间表ids
     * @param dishIds
     * @return
     */
    List<Long> selectSetmealDishIdsByDishIds(Long[] dishIds);

    /**
     * 保存套餐和菜品关系
     * @param setmealDishes
     */
    void insertBatch(List<SetmealDish> setmealDishes);

    /**
     * 根据setmealIds删除setmeal_dis中的数据
     * @param setmealIds
     */
    void deleteBysetmealIds(Long[] setmealIds);

    /**
     * 根据id查询setmael_dish表中数据，并返回Array<SetmealDish>数组
     * @param id
     * @return
     */
    @Select("select id, setmeal_id, dish_id, name, price, copies from setmeal_dish where setmeal_id = #{setmealId}")
   ArrayList<SetmealDish> selectBySetmealId(long setmealId);
}
